package graphAndAnswer;

import java.util.ArrayList;
import java.util.HashMap;

import interfaces.Answer;

public class ModuleHandleidingGraphAnswer implements Answer {
	private HashMap<String, Integer> earlyTimes = new HashMap<String, Integer>();
	private HashMap<String, Integer> lastTimes = new HashMap<String, Integer>();
	private ArrayList<String> topologicalPath = new ArrayList<String>();

	public ModuleHandleidingGraphAnswer() {
		addEarlyAnswers();
		addLastAnswers();
		addTopoPath();
	}

	@Override
	public String getAnswer(String NodeLetter) {
		String format = "X(Y-Z)";
		String answer = format.replace("X", NodeLetter);
		answer = answer.replace("Y", "" + checkEarly(NodeLetter));
		answer = answer.replace("Z", "" + checkLast(NodeLetter));
		return answer;
	}

	@Override
	public String getTopo(int position) {
		return topologicalPath.get(position);
	}

	@Override
	public int checkEarly(String NodeLetter) {
		return earlyTimes.get(NodeLetter);
	}

	@Override
	public int checkLast(String NodeLetter) {
		return lastTimes.get(NodeLetter);
	}

	@Override
	public void addEarlyAnswers() {
		earlyTimes.put("A", 0);
		earlyTimes.put("B", 3);
		earlyTimes.put("C", 6);
		earlyTimes.put("D", 1);
		earlyTimes.put("E", 2);
		earlyTimes.put("F", 5);
		earlyTimes.put("G", 3);
	}

	@Override
	public void addLastAnswers() {
		lastTimes.put("A", 0);
		lastTimes.put("B", 4);
		lastTimes.put("C", 6);
		lastTimes.put("D", 3);
		lastTimes.put("E", 4);
		lastTimes.put("F", 5);
		lastTimes.put("G", 3);
	}

	@Override
	public void addTopoPath() {
		topologicalPath.add("A");
		topologicalPath.add("B");
		topologicalPath.add("D");
		topologicalPath.add("G");
		topologicalPath.add("E");
		topologicalPath.add("F");
		topologicalPath.add("C");
	}
}
